//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
var selectid = [];
// var payma='';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    uid: "",
    // 页数
    pageIndex: 1,
    // 上拉加载数组
    onReachBottomData: [],
    resultMsg: "",
    state: '',
    management_good: false,
    pickerHidden: true,
    chosen: '',
    uidlist: '',
    payma: '',
    hiddensubmit: true,
    nocancel: false,
    // 批量选中数组
    // selectid: [],
    payma1: '',

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var uid = wx.getStorageSync('uid');
    this.setData({
      uid: uid,

    })
    this.GetPersonMemberList();
  },

  // 推荐人查看自己名下推荐的个人用户
  GetPersonMemberList: function () {
    var that = this;
    var uid = this.data.uid;
    var onReachBottomData = this.data.onReachBottomData;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=LockerGetPersonMemberList&UID=" + uid),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        console.log(json);
        for (var i = 0; i < json.length; i++) {
          onReachBottomData.push(json[i])
        }
        that.setData({
          onReachBottomData: onReachBottomData,
        })

      }
    })
  },
  // 批量管理
  onClick: function () {
    var that = this;
    that.setData({
      management_good: true,
    })
  },

  pickerConfirm(e) {
    this.setData({
      pickerHidden: true
    })
    this.setData({
      chosen: e.detail.value
    })

  },

  pickerCancel() {
    this.setData({
      pickerHidden: true
    })
  },

  pickerShow() {
    this.setData({
      pickerHidden: false
    })
  },
  // 弹框输入额度-取消
  cancel: function () {
    this.setData({
      hiddensubmit: true
    });
  },
  // 拨付激励码获取
  MaInput: function (e) {
    console.log(e)
    var payma = this.data.payma;
    this.setData({
      payma: e.detail.value,
    })
  },
  // 拨付激励码获取
  // MaInput1: function (e) {
  //   console.log(e)
  //   this.setData({
  //     payma1: e.detail.value,
  //   })
  // },
  // 拨付激励-modal弹框
  formSubmit(e) {
    // console.log(e)
    var that = this;
    var id = e.currentTarget.dataset.id
    var hiddensubmit = this.data.hiddensubmit;
    that.setData({
      hiddensubmit: !this.data.hiddensubmit,
      id: id
    })
  },
  // 批量选中-数组
  checkproductChange: function (e) {
    var checkbox = e.detail.value;
    for (var i = 0; i < checkbox.length; i++) {
      var selectrow = checkbox[i].split(";")
      selectid = selectid.concat(selectrow[i])
    }
    this.setData({
      selectid: selectid.splice(checkbox, 1),
    })
    console.log(selectid)
  },

  // 弹框输入额度-确定
  confirm: function (e) {
    var that = this;
    var uid = this.data.uid;
    var uidlist = this.data.id;
    var payma = this.data.payma;
    var management_good = this.data.management_good;
    // console.log(payma)
    if (!management_good) {
      console.log("method=LockerPayMaToPersonMember&UID=" + uid + "&UIDList=" + uidlist + "&PayMa=" + payma);
      wx.request({
        url: baseJs.api + baseJs.encryUrl("method=LockerPayMaToPersonMember&UID=" + uid + "&UIDList=" + uidlist + "&PayMa=" + payma),
        success: function (res) {
          var json = JSON.parse(baseJs.decryUrl(res.data));
          uidlist = json.ResultData.UIDList;
          payma = json.ResultData.PayMa;
          console.log(json);
          if (json.ResultFlag == 1) {
            wx.showToast({
              title: json.ResultMsg,
              icon: 'none',
              duration: 2000
            });
            setTimeout(function () {
              wx.navigateBack({
                delta: 1
              })
            }, 1000)
          }
          if (json.ResultFlag == 0) {
            wx.showToast({
              title: json.ResultMsg,
              icon: 'none',
              duration: 2000
            });
          }

        }
      })
    } else {
      console.log("method=LockerPayMaToPersonMember&UID=" + uid + "&UIDList=" + selectid + "&PayMa=" + payma);
      wx.request({
        url: baseJs.api + baseJs.encryUrl("method=LockerPayMaToPersonMember&UID=" + uid + "&UIDList=" + selectid + "&PayMa=" + payma),
        success: function (res) {
          var json = JSON.parse(baseJs.decryUrl(res.data));
          selectid = json.ResultData.UIDList;
          payma = json.ResultData.PayMa;
          console.log(json);
          if (json.ResultFlag == 1) {
            wx.showToast({
              title: json.ResultMsg,
              icon: 'none',
              duration: 2000
            });
            setTimeout(function () {
              wx.navigateBack({
                delta: 1
              })
            }, 1000)
          }
          if (json.ResultFlag == 0) {
            wx.showToast({
              title: json.ResultMsg,
              icon: 'none',
              duration: 2000
            });
          }

        }
      })
    }
    this.setData({
      hiddensubmit: true
    });

  },
  // 取消
  formReset(e) {
    console.log(e)
    this.setData({
      uidlist: '',
      selectid: '',
    })
  },
})